CFLAGS=-m32 -g -ggdb -Wall -Werror -O0 -fno-zero-initialized-in-bss -fno-stack-protector -ffreestanding
LDFLAGS=-static -m elf_i386 --oformat binary -b elf32-i386 -e start -Ttext 0x1200

all: diskette.img

run: diskette.img
	@echo c|bochs -q

disk: diskette.img kernel.bin
	sudo dd if=diskette.img of=/dev/fd0 count=1
	sudo mcopy -oi /dev/fd0 kernel.bin ::/

diskette.img: kernel.bin
	@echo "writing disk image"
	@mcopy -oi diskette.img kernel.bin ::/

asm.o: asm.asm
	@echo "making kernel"
	@nasm -felf32 asm.asm -o asm.o

gdt.o: gdt.c
	@echo "making gdt"
	@gcc $(CFLAGS) -c -o gdt.o gdt.c

idt.o: idt.c
	@echo "making idt"
	@gcc $(CFLAGS) -c -o idt.o idt.c

isr.o: isr.asm
	@echo "making isr"
	@nasm -felf32 isr.asm -o isr.o

kernel.bin: asm.o gdt.o idt.o isr.o
	@echo "linking kernel"
	@ld $(LDFLAGS) asm.o gdt.o idt.o isr.o -o kernel.bin
